package com.irssproject.app.web.action.lectorRSS;

import java.util.Map;

import com.irssproject.app.bean.main.Usuari;
import com.irssproject.app.service.lectorRSS.iface.SubscripcioService;
import com.irssproject.app.utils.Constants;
import com.opensymphony.xwork2.ActionContext;
import com.opensymphony.xwork2.ActionSupport;


@SuppressWarnings("serial")
public class VotarItemAction extends ActionSupport {

	
	private String feedURL;
	
	private String itemURL;
	
	private String magrada;
	
	private boolean valoracio;
	
	private Long idLectura;
	
	public Long getIdLectura() {
		return idLectura;
	}



	public void setIdLectura(Long idLectura) {
		this.idLectura = idLectura;
	}

	SubscripcioService subscripcioService;
	
	public VotarItemAction(SubscripcioService subscripcioService) {
		this.subscripcioService = subscripcioService;
	}
	

	
	public String getItemURL() {
		return itemURL;
	}

	public void setItemURL(String itemURL) {
		this.itemURL = itemURL;
	}

	public String getFeedURL() {
		return feedURL;
	}

	public void setFeedURL(String feedURL) {
		this.feedURL = feedURL;
	}
	
	public void setMagrada(String magrada) {
		this.magrada = magrada;
	}

	public String getMagrada() {
		return magrada;
	}

	public String votarLectura(){

		try
		{
			Map<String, Object> session = ActionContext.getContext().getSession();
			boolean val = subscripcioService.valorarLectura(idLectura);
			setValoracio(val);
			session.put(Constants.MAGRADA, !val);
		}
		catch (Exception e) 
		{
			e.printStackTrace();
		}

		return SUCCESS;
	}



	public void setValoracio(boolean valoracio) {
		this.valoracio = valoracio;
	}



	public boolean isValoracio() {
		return valoracio;
	}


}
